Skip to content

Conversation

@shahinataei-ts
Copy link
Contributor

Summary

  • Fix incorrect parameter passing in mapGraphQLTypeToPHPType for ListOfType

Problem

When processing ListOfType, the $builtInOnly parameter was passed as the second argument ($nullable) instead of the third argument ($builtInOnly):

// Before (bug)
return SymfonyType::list($this->mapGraphQLTypeToPHPType($type->getWrappedType(), $builtInOnly));

// After (fix)
return SymfonyType::list($this->mapGraphQLTypeToPHPType($type->getWrappedType(), null, $builtInOnly));

This caused $builtInOnly to default to false, resulting in the PHP mapped type being used instead of the primitive JSON type in $data parameter docblocks.

Example

// Config
->withScalar('Currency', Type::string(), Type::object(Currency::class))

// GraphQL: currencies: [Currency!]!

// Generated (wrong):  'currencies': list<Currency>
// Should be:          'currencies': list<string>

PHPStan Error

This bug caused PHPStan errors in generated code:

Parameter #1 $code of class Money\Currency constructor expects non-empty-string, Money\Currency given.

Affected Types

Any custom scalar where the primitive type differs from the PHP type, when used in a list:

  • [Currency!]! (string → Money\Currency)
  • [DateTime!]! (string → DateTimeImmutable)
  • [Country!]! (string → Country enum)

@ruudk ruudk changed the title Fix: Pass builtInOnly parameter correctly for list types Pass builtInOnly parameter correctly for list types Dec 16, 2025
When processing ListOfType in mapGraphQLTypeToPHPType, the $builtInOnly
parameter was incorrectly passed as the second argument ($nullable)
instead of the third argument ($builtInOnly).

This caused the $builtInOnly parameter to default to false when
processing list items, resulting in the PHP mapped type being used
instead of the primitive JSON type in $data parameter docblocks.

Example of the bug:
- GraphQL: currencies: [Currency!]!
- Config: withScalar('Currency', Type::string(), Type::object(Currency::class))
- Generated docblock: 'currencies': list<Currency>  (wrong)
- Should be: 'currencies': list<string>  (correct)

This caused PHPStan errors like:
"Parameter ruudk#1 $code of class Money\Currency constructor expects
non-empty-string, Money\Currency given."
@shahinataei-ts shahinataei-ts force-pushed the fix/list-scalar-builtin-type-mapping branch from 97b518d to 2051fa9 Compare December 16, 2025 12:36
@shahinataei-ts shahinataei-ts changed the title Pass builtInOnly parameter correctly for list types Fix: Pass builtInOnly parameter correctly for list types Pass builtInOnly parameter correctly for list types Dec 16, 2025
Copy link
Owner

@ruudk ruudk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ruudk ruudk changed the title Fix: Pass builtInOnly parameter correctly for list types Pass builtInOnly parameter correctly for list types Pass builtInOnly parameter correctly for list types Pass builtInOnly parameter correctly for list types Dec 16, 2025
@ruudk ruudk changed the title Pass builtInOnly parameter correctly for list types Pass builtInOnly parameter correctly for list types Pass builtInOnly parameter correctly for list types Dec 16, 2025
@ruudk ruudk merged commit 90ab8fb into ruudk:main Dec 16, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants